import { _decorator, Component, Node, tween, Tween, Vec2, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Fish')
export class Fish extends Component {

    @property([Node])
    private FishArr: Node[] = [];

    //当前索引
    public NowIndex: number = 0;


    /**
     * 更新
     */
    public UpdateFish(_index: number) {
        this.NowIndex = _index;
        for (let i = 0; i < this.FishArr.length; i++) {
            this.FishArr[i].active = i == _index;
        }
    }

    /**
     * 播放出现动画
     */
    public PlayShowAni(_delay: number) {
        Tween.stopAllByTarget(this.node);

        this.FishArr[this.NowIndex].setPosition(new Vec3(500, 500, 0))
        tween(this.FishArr[this.NowIndex]).delay(_delay * 0.1).to(0.3, { position: new Vec3(0, 0, 0) }).start();
    }

    /**
     * 更新
     */
    public UpdateFish1(_index: number, _pos: Vec3) {
        this.NowIndex = _index;
        for (let i = 0; i < this.FishArr.length; i++) {
            this.FishArr[i].active = i == _index;
        }

        this.FishArr[_index].setWorldPosition(_pos);
        tween(this.FishArr[_index]).to(0.5, { scale: new Vec3(0.4, 0.4, 0.4), position: new Vec3(0, 0, 0) }, { easing: 'backIn' }).start();
    }
}


